package com;

import com.fz.entity.Yang;
import com.fz.mapper.StudentMapper;
import com.fz.mapper.YangMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.omg.CORBA.Object;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by ZCY on 2018-01-16.
 */
public class Demo {
    @Test
    public void abc(){
        try {
            SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-conf.xml"));
            /*这里的session与HttpSession是不一样的，这里的session是数据库的会话*/
            SqlSession session = sf.openSession();
            /*得到学生的信息*/
            StudentMapper sdao = session.getMapper(StudentMapper.class);
            List<Map<String, Object>> v = sdao.query();
            for (Map<String ,Object> m:v){
               for(String s:m.keySet()){
                   System.out.println(m.get(s));
               }
               System.out.println("------------");
            }

            /*得到Yang的信息*/
            YangMapper bdao = session.getMapper(YangMapper.class);
            List<Yang> yang = bdao.query();
            for(Yang y: yang){
                System.out.println(y);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
